package com.road.yishi.protocol;

import java.util.HashMap;
import java.util.Map;

/**
 * <pre>
 * 客户端协议过滤
 * author: rick.han
 * date  : 2014/08/27
 * desc  : 以castleProtocol为例 ，有四百多条消息码，而真正是客户端发上来的部分，只有三百多条
 * 		      ，如果客户端自己组包遍历消息码时，可能很轻易的找到那些隐藏于服务器之间的通信消息码
 * 		      ，因此需要对客户端的消息码进行一下过滤，同时在后续写代码中需要特别注意一下，如果不
 * 		      是客户端 交互相关的消息码（主要是指客户端向服务端发的消息），要么做好必要的校验，假
 * 		     设客户端也能发 这样的消息，要么加在下面的屏蔽列表里
 * </pre>
 */
public class ClientProtoFilter {

	private static int[] forbidCode = new int[] { // 此数组由程序生成，如果消息码改动较大，则需重新生成
			// castleserver部分
			0x2328, 0x2327, 0x2329, 0x232A, 0x232B, 0x232C, 0x1389, 0x138A, 0x138B, 0x1395, 0x13B0, 0x1410, 0x1412,
			0x1423, 0x1424, 0x1425, 0x1426, 0x142B, 0x142C, 0x142D, 0x142E, 0x1430, 0x1431, 0x1439, 0x153C, 0x1600,
			0x2001, 0x2003, 0x201D, 0x2021, 0x2022, 0x2023, 0x2024, 0x2025, 0x203C, 0x2046, 0x2047, 0x2050,
			0x2051, 0x2052, 0x2054, 0x2058, 0x205C, 0x2084, 0x2096, 0x2115, 0x211B, 0x211C, 0x2126, 0x2127, 0x2140,
			0x2143, 0x2145, 0x2148, 0x214A, 0x214B, 0x2153, 0x215F, 0x2170, 0x2171, 0x2173, 0x2174, 0x2178, 0x2179,
			0x217A, 0x217B, 0x217D, 0x217F, 0x2180, 0x2185, 0x2187, 0x2188, 0x2189, 0x218B, 0x218C, 0x218F, 0x2194,
			0x2198, 0x2199, 0x219A, 0x219B, 0x219D, 0x219E, 0x219F, 0x2202, 0x2203, 0x2204, 0x2205, 0x2208, 0x2209,
			0x220F, 0x21A0, 0x21A1, 0x21A2,
			0x21A3,
			0x21A4,
			0x21A5,
			0x21A6,
			0x21A7,
			0x21A8,
			0x21A9,
			0x21AA,
			0x21AB,
			0x21B2,
			0x21B3,
			0x21B4,
			0x2524,
			0x217C,// castleserver 结束 //0x2026战斗取消可以通过客户端

			// battleserver
			0x2AF8, 0x2711, 0x2712, 0x2715, 0x2716, 0x271B, 0x271C, 0x271D, 0x271E, 0x2721, 0x2723, 0x2725, 0x2800,
			0x2801, 0x2900, 0x2902, 0x2904, 0x2905, 0x2906,
			0x2909,
			0x290A,
			0x290C,
			0x36B0,

			// gateway
			0x4E22, 0x4E25, 0x4E26, 0x4E27, 0x5000, 0x5001, 0x5002, 0x5003, 0x5004, 0x5005, 0x5101, 0x5102, 0x5103,
			0x5104, 0x5105, 0x5106, 0x5107, 0x5006, 0x5007, 0x5008, 0x5009, 0x5010, 0x5011, 0x5012, 0x5014, 0x5018,
			0x501c,
			0x501D,
			0x501E,

			// chatserver
			0x3B60, 0x3A99, 0x3A9A, 0x3A9E, 0x3A9F, 0x3AA0, 0x3AA1, 0x3AA2, 0x3AA3, 0x3AA6, 0x3AA7, 0x3AA8, 0x3AAA,
			0x3AAB, 0x3AAC, 0x3AAD, 0x3AAE, 0x3AB6, 0x3AB7, 0x3AB8, 0x3ABA, 0x3ABB, 0x3ABD, 0x3ABF, 0x3AC1, 0x3AC5,
			0x3AC6, 0x3AC7, 0x3AC8, 0x3AC9,

			// crossserver
			0x6720, 0x61B0, 0x61B1, 0x61b2, 0x6200, 0x6201, 0x6202, 0x6203, 0x6204, 0x6205, 0x6206, 0x6207, 0x620A,
			0x620B, 0x620C, 0x620D, 0x620E, 0x620F, 0x6210, 0x6211, 0x6212, 0x6213, };

	private static Map<Integer, Boolean> forbidMap = new HashMap<Integer, Boolean>();

	static {
		for (int code : forbidCode) {
			forbidMap.put(code, true);
		}
	}

	/**
	 * <pre>
	 * 判断消息码能否通过
	 * </pre>
	 * 
	 * @param code
	 * @return
	 */
	public static boolean canPass(int code) {
		if (forbidMap.containsKey(code)) {
			return false;
		}

		return true;
	}
}
